<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        [v-cloak] {
            display: none; /*隐藏元素*/
        }
    </style>
</head>
<body>
<table v-cloak border="1">
    <caption>员工列表</caption>
    <tr>
        <th>id</th>
        <th>名字</th>
        <th>工资</th>
        <th>工作</th>
        <th>操作</th>
    </tr>
    <tr v-cloak v-for="emp in arr">
        <th>{{emp.id}}</th>
        <th><a :href="'/update.html?id='+emp.id">{{emp.name}}</a></th>
        <th>{{emp.sal}}</th>
        <th>{{emp.job}}</th>
        <!-- : href 属性绑定-->
        <th><a href="#" @click="del(emp.id)">删除</a></th>
    </tr>
</table>
<!--引入Vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<!--引入Axios-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    let vm = new Vue({
        el: "table",
        data: {
            arr: []
        },
        created: function () {
            //发出异步请求
            axios.get("/select").then(function (response) {
                vm.arr = response.data;

            })

        },
        methods: {
            del: function (id) {
                if (confirm("您确认删除吗?")) {
                    //发出异步请求
                    axios.get("/delete?id=" + id).then(function () {
                        alert("删除成功!");
                        location.reload();//刷新

                    })
                }
            }
        }
    })
</script>
</body>
</html>